package system

import (
	"atools/models"
	"atools/utils"
	"bytes"
	"os/exec"
	"strings"
)

type LinuxInfo struct {
}

func (linux LinuxInfo) GetInstalledApps(app *App) []models.InstalledApp {
	// 简化：列出 /usr/bin 中常见应用
	cmd := exec.Command("ls", "/usr/bin")
	var out bytes.Buffer
	cmd.Stdout = &out
	err := cmd.Run()
	if err != nil {
		return nil
	}

	common := map[string]bool{
		"firefox":     true,
		"chrome":      true,
		"code":        true,
		"gedit":       true,
		"vlc":         true,
		"libreoffice": true,
	}

	var apps []models.InstalledApp
	for _, line := range strings.Split(out.String(), "\n") {
		if common[strings.TrimSpace(line)] {
			appName := strings.TrimSpace(line)
			apps = append(apps, models.InstalledApp{
				Name:    appName,
				EnName:  utils.GetPingYin(appName),
				Path:    "/usr/bin/" + appName,
				AppType: "InstallApp",
			})
		}
	}
	return apps
}
